//
//  WorkmatePageControl.m
//  MyProject
//
//  Created by 石小强 on 2018/4/16.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "WorkmatePageControl.h"

#define dotW 13
#define dotH 3
#define margin 7

@implementation WorkmatePageControl

- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 计算原点间距
    CGFloat marginX = dotW + margin;
    
    // 计算整个pageControl的宽度
    CGFloat newW = (self.subviews.count - 1) * marginX;
    
    // 设置新frame
    self.frame = CGRectMake((kScreenWidth - 30 - newW - dotW) * 0.5, self.frame.origin.y, newW + dotW, self.frame.size.height);
    
    // 遍历subview，设置原点frame
    for (NSInteger i = 0; i < [self.subviews count]; i++) {
        UIImageView *dot = [self.subviews objectAtIndex:i];
        if (i == self.currentPage) {
            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dotH)];
        } else {
            [dot setFrame:CGRectMake(i * marginX, dot.frame.origin.y, dotW, dotH)];
        }
    }
}

@end
